home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 220 / 220.xpi / install.js < prev    next >
Text File  |  2010-01-24  |  4KB  |  120 lines

  1. const APP_DISPLAY_NAME = "FlashGot";
  2. const APP_NAME = "flashgot";
  3. const APP_PACKAGE = "/informaction/flashgot";
  4. const APP_VERSION = "1.2.1.10";
  5.  
  6. const APP_PREFS_FILE="defaults/preferences/flashgot.js";
  7. const APP_XPCOM_SERVICE="components/flashgotService.js";
  8. const APP_JAR_FILE = "flashgot.jar";
  9. const APP_CONTENT_FOLDER = "content/flashgot/";
  10. const APP_LOCALES = [
  11.   "it-IT","th-TH","de-DE","nl-NL", 
  12.   "ru-RU","es-ES","es-AR", "es-CL", // "ms-MY",
  13.   "hu-HU", "sv-SE","fr-FR", "fi-FI",
  14.   "he-IL","tr-TR","sr-YU", "ca-AD",
  15.   "zh-TW","zh-CN","el-GR", "uk-UA",
  16.   "lt-LT","ja-JP","pl-PL", "hr-HR",
  17.   "id-ID","cs-CZ","ko-KR", "be-BY",
  18.   "nb-NO","ro-RO","sk-SK",
  19.   "fa-IR","sl-SI","ar-JO",
  20.   "bg-BG","da-DK","pt-BR",
  21.   "pt-PT","sq-AL",
  22.   "am-HY","ar","ar-SA","hi-IN","km-KH",
  23.   "mn-MN","vi-VN","gl-ES",
  24.   "en-US" 
  25.   ];
  26.  
  27. const APP_SUCCESS_MESSAGE = APP_DISPLAY_NAME+" should now be available in your context menu when you restart Mozilla.";
  28.  
  29. var instToProfile = false;
  30.  
  31. myPerformInstall(false);
  32.  
  33. function myPerformInstall(secondTry) {
  34.   
  35.   var err;
  36.   initInstall(APP_NAME, APP_PACKAGE, APP_VERSION);
  37.   
  38.   var err;
  39.   initInstall(APP_NAME, APP_PACKAGE, APP_VERSION);
  40.   var profChrome = getFolder("Profile", "chrome");
  41.   if(!secondTry) {  
  42.     File.remove(getFolder(profChrome, APP_JAR_FILE));
  43.   }
  44.  
  45.   var chromef = instToProfile ? profChrome : getFolder("chrome");
  46.   err = addFile(APP_PACKAGE, APP_VERSION, "chrome/" + APP_JAR_FILE, chromef, null);
  47.    
  48.   if(APP_PREFS_FILE && (err == SUCCESS) ) {
  49.     const prefDirs=[
  50.       getFolder(getFolder("Profile"),"pref"),
  51.       getFolder(getFolder(getFolder("Program"),"defaults"),"pref")
  52.       ];
  53.     for(var j=prefDirs.length; j-->0;) {
  54.       var prefDir=prefDirs[j];
  55.       if(!File.exists(prefDir)) {
  56.         File.dirCreate(prefDir);
  57.       }
  58.       err = addFile(APP_PACKAGE, APP_VERSION,  APP_PREFS_FILE, prefDir, null, true);
  59.       logComment("Adding "+APP_PREFS_FILE+" in "+prefDir+": exit code = "+err);
  60.     }
  61.   }
  62.   
  63.   if(err == SUCCESS) {
  64.     var jar = getFolder(chromef, APP_JAR_FILE);
  65.     const chromeFlag=instToProfile?PROFILE_CHROME:DELAYED_CHROME;
  66.   
  67.     registerChrome(CONTENT | chromeFlag, jar, APP_CONTENT_FOLDER);
  68.     var localesCount=APP_LOCALES.length;
  69.     if(localesCount>0) {
  70.       registerChrome(LOCALE | chromeFlag, jar, "content/flashgot/"+APP_LOCALES[--localesCount]+"/");
  71.       while(localesCount-- >0) {
  72.         registerChrome(LOCALE  | chromeFlag, jar, "locale/"+APP_LOCALES[localesCount]+"/flashgot/");
  73.       }
  74.     }
  75.     registerChrome(SKIN | chromeFlag, jar, "skin/classic/flashgot/");
  76.     
  77.     
  78.     if(APP_XPCOM_SERVICE) {
  79.       var componentsDir = getFolder("Components");
  80.       /*
  81.       if (!(APP_XPCOM_SERVICE instanceof Array)) {
  82.         APP_XPCOM_SERVICE = [APP_XPCOM_SERVICE];
  83.       }
  84.       for (var s = APP_XPCOM_SERVICE.length; s-- > 0;)
  85.         addFile(APP_PACKAGE,APP_VERSION, APP_XPCOM_SERVICE[s], componentsDir, null, true);
  86.       */
  87.       addFile(APP_PACKAGE,APP_VERSION, APP_XPCOM_SERVICE, componentsDir, null, true);
  88.       addFile(APP_NAME, "components/.autoreg", getFolder("Program"), "");
  89.     }
  90.     
  91.     err = performInstall();
  92.     if(err == -239 && !secondTry) {
  93.       alert("Chrome registration problem, maybe transient, retrying...");
  94.       cancelInstall(err);
  95.       myPerformInstall(true);
  96.       return;
  97.     }
  98.     if(err == SUCCESS || err == 999) {
  99.       alert(APP_DISPLAY_NAME+" "+APP_VERSION+" has been succesfully installed in your " + 
  100.           (instToProfile ? "profile" : "browser") +
  101.           ".\n" + APP_SUCCESS_MESSAGE);
  102.     } else {
  103.       var msg = "Install failed!!! Error code:" + err;
  104.  
  105.       if(err == -239) {
  106.         msg += "\nThis specific error is usually transient:"
  107.           +"\nif you retry to install again, it will probably go away."
  108.       }
  109.  
  110.       alert(msg);
  111.       cancelInstall(err);
  112.     }
  113.   } else {
  114.     alert("Failed to create " +APP_JAR_FILE +"\n"
  115.       +"You probably don't have appropriate permissions \n"
  116.       +"(write access to your profile or chrome directory). \n"
  117.       +"_____________________________\nError code:" + err);
  118.     cancelInstall(err);
  119.   }
  120. }